package src;

import jargs.gnu.CmdLineParser;
import jargs.gnu.CmdLineParser.IllegalOptionValueException;
import jargs.gnu.CmdLineParser.UnknownOptionException;
import lib.messaging.NetworkAddress;

public class ClientConfiguration
{
    public static final String ClientName = "localhost";
    public static final String ClientPrompt = "Client$ ";
    public static final String ExitCommandName = "q";
    private static final String PacketDropProbabilityArgLongName = "dropPacketProbability";
    private static final char PacketDropProbabilityArgShortName = 'd';
    private static final String PortArgLongName = "port";
    private static final char PortArgShortName = 'p';
    public static final String ServerName = "localhost";
    public static final int Timeout = 0;
    public static final String UserFileSuffix = ".txt";

    public static ClientConfiguration ReadConfiguration(String[] args)
            throws IllegalOptionValueException, UnknownOptionException
    {

        CmdLineParser parser = new CmdLineParser();
        CmdLineParser.Option portOption = parser.addStringOption(PortArgShortName, PortArgLongName);
        CmdLineParser.Option packetDropProbabilityOption = parser.addStringOption(
                PacketDropProbabilityArgShortName,
                PacketDropProbabilityArgLongName);
        parser.parse(args);

        String port = (String) parser.getOptionValue(portOption);
        NetworkAddress clientAddress = new NetworkAddress(ClientName, Integer.parseInt(port));

        String packetDropProbability = (String) parser.getOptionValue(packetDropProbabilityOption);

        ClientConfiguration config = new ClientConfiguration();
        config.clientAddress = clientAddress;
        config.clientPacketDropProbability = Double.parseDouble(packetDropProbability);
        return config;
    }

    private NetworkAddress clientAddress;
    private double clientPacketDropProbability;

    public NetworkAddress ClientAddress()
    {
        return clientAddress;
    }

    public double ClientPacketDropProbability()
    {
        return clientPacketDropProbability;
    }
}
